<?php
# 文件名称:feedback.php
# MetInfo在线反馈系统 
# Copyright (C) 长沙米拓信息技术有限公司 (http://www.metinfo.cn). All rights reserved.
class feedback extends C_controller {
	function feedback()
	{
		parent::C_controller();
		//设置语言
		$this->setLanguageFile( 'feedback' );		
		$this->registerTask( 'add'  , 	'display'  );
		$this->registerTask( 'edit'  , 	'display'  );
		$this->registerTask( 'apply', 	'save'  );
	}
	
	function display()
	{
		
		$SYS = &get_instance();
		//判断是否有权限
		$this->permit('feedback.display');
		//应用还是保存任务
		if($this->getTask()=='apply')
		{
			$tmp[] = $SYS->request->getVar('id', 0, 'post', 'int');
			$SYS->request->setVar('cid', $tmp, 'post', 'int');
			parent::display($SYS->request->getVar('apply',''));
		}	
		else
		{
			parent::display($this->getTask());
		}
	}
	function sendMail($data)
	{
		$SYS = &get_instance();
		$CFG = &$SYS->config;
		$SYS->loader->helper('mail');
		$this->_maildata = $data;
		//$data['mailtpl']
		ob_start("mailtpl");
		include PATH_THEMES.DS.$CFG->item('theme').DS.'mailtpls'.DS.$data['mailtpl'];
		$body = ob_get_contents();
		ob_end_clean();
		sendEmail(array('subject'=>$data['subject'],'toaddress'=>$data['email'],'body'=>$body));		
	}
	function save()
	{
		C_request::checkToken();
		$this->permit('feedback.edit');
		$SYS = &get_instance();
		//初始化数据
		$data = $SYS->request->get('post',4);
		$data['id'] = $SYS->request->getVar('id', 0, 'post', 'int');
		$data['data']=serialize(C_html::_('select.toObjects',$data['feedback']));
		$data['readok']=1;
		$isNew	= true;
		$id = $data['id'];
		//获取feedback表类
		$table = C_loader::getDTO('feedback');
		if ($id > 0) {
			$table->load($id);
			$isNew = false;
		}
		// 绑定数据
		if (!$table->bind($data)) {
			$SYS->loader->setMessage(C_text::sprintf( 'Tip5'),'error');
			$this->display();
			return;
		}
		// 验证数据
		if (!$table->check()) {
			$SYS->loader->setMessage(C_text::sprintf( 'Tip5'),'error');
			$this->display();
			return;
		}
		// 保存
		if (!$table->store()) {
			$SYS->loader->setMessage(C_text::sprintf( 'Tip5'),'error');
			$this->display();
			return;
		}
		$msg = '';
		$this->sendMail($data);
		// 更新自己时
		switch ( $this->getTask() )
		{
			case 'apply':
				$msg = C_text::sprintf( 'Tip1');
				break;
			case 'save':
			default:
				$msg = C_text::sprintf( 'Tip2');
				break;
		}
		$SYS->loader->setMessage($msg);
		$this->display();
	}
	
	function remove()
	{
		C_request::checkToken();
		$this->permit('feedback.remove');
		$SYS = &get_instance();
		$cid = $SYS->request->getVar( 'cid', array(), '', 'array' );
		$table = C_loader::getDTO('feedback');
		if (count( $cid ) < 1) {
			return ;
		}
		$msg = '';
		foreach ($cid as $id)
		{
			$table->load($id);
			// 删除
			$table->delete();
			$msg = '';
		}
		$SYS->loader->setMessage(C_text::_('Tip3'));
		$this->display();
	}
	function cancel( )
	{
		$this->display();
	}
}
# 本程序是一个开源系统,使用时请你仔细阅读使用协议,商业用途请自觉购买商业授权.
# Copyright (C) 长沙米拓信息技术有限公司 (http://www.metinfo.cn). All rights reserved.
?>